package ui;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.imageio.ImageIO;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;

import model.Customer;
import model.Service;
import model.SubContractor;
import util.ImagePanel;
import util.JCalendar;
import util.PdfFilePrint;
import controller.CustomerController;
import controller.OfferController;
import controller.ProjectController;
import controller.SubContractorController;

public class OfferUI implements ActionListener
{
	private boolean startup = false;

	private static OfferUI instance = null;

	private OfferController svCtrl;
	private CustomerController cusCtrl;
	private SubContractorController subCtrl;
	private ProjectController pjCtrl;

	private JFrame frameOfferUI;

	private JTabbedPane tabbedPane;

	private ImagePanel newOffers;
	private ImagePanel allOffers;

	private Image image = null;

	private JLabel offers;
	private JLabel offers_1;
	private JLabel offerDrawNo;
	private JLabel offerQuantity;
	private JLabel offerDescr;
	private JLabel offerCus;
	private JLabel dimensionLabel;
	private JLabel offerPrice;

	private JLabel searchBy;
	private JLabel searchWith;

	private JCalendar cal;

	private JTable allOfferTable;

	private DefaultTableModel allOfferTableModel;
	private DefaultTableModel allSubsModel;

	private JScrollPane allOfferTableScroll;

	private JScrollPane descrScroll;

	private JComboBox<String> allOfferSearch;
	private JComboBox<String> newOfferCustomerSelection;
	private JComboBox<String> subContractor;

	private JButton createOffer;
	private JButton emptySearchList;
	private JButton editOffer;
	private JButton statistics;
	private JButton descriptionBut;
	private JButton changeStatus;
	private JButton projectMaker;
	private JButton add;

	private JTextField offerSearch;

	private JTextField offerField;
	private JTextField offerDrawNoField;
	private JTextField offerQuantityField;
	private JTextField dimensionText;
	private JTextField priceText;
	private JTextField prices;
	private JTextField projLink;

	private JTextPane offerDescrField;

	private JCheckBox active;

	private ArrayList<Service> offerList;
	private ArrayList<Customer> cusList;
	private ArrayList<SubContractor> sub;
	private ArrayList<Double> price;

	private String column[] = {"id", "name"};
	private JButton btnBack;

	private backButton back;
	private JButton btnPrint;

	public void display()
	{
		frameOfferUI.setSize(800, 400);
		frameOfferUI.setVisible(true);
		frameOfferUI.setResizable(false);
		frameOfferUI.setLocationRelativeTo(null);
	}

	public OfferUI()
	{
		frameOfferUI = new MainWindow();

		back = new backButton();
		back.setNumber("10");

		allSubsModel = new DefaultTableModel(null, column);
		price = new ArrayList<Double>();

		offers = new JLabel("Offers");
		offers.setBounds(9, 1, 116, 28);
		offers.setForeground(Color.white);
		offers.setFont(new Font("Dialog", Font.BOLD, 20));

		frameOfferUI.getContentPane().add(offers);

		statistics = new JButton();
		statistics.setLocation(691, 326);
		statistics.setSize(100, 20);
		statistics.setOpaque(false);
		statistics.setText("Statistics");
		statistics.addActionListener(this);

		frameOfferUI.getContentPane().add(statistics);

		try
		{
			image = ImageIO.read(new File("img/background/background.jpg"));
		}
		catch(Exception e)
		{
			//msgError(null, "Could not load background");
		}
		tabbedPane = new JTabbedPane();
		tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
		tabbedPane.setBounds(0, 31, 800, 289);

		frameOfferUI.getContentPane().add(tabbedPane);

		// all Requests panel

		allOffers = new ImagePanel(image);
		allOffers.setBounds(0,31,694, 289);

		emptySearchList = new JButton();
		emptySearchList.setText("Clear Search");
		emptySearchList.setOpaque(false);
		emptySearchList.addActionListener(this);

		descriptionBut = new JButton();
		descriptionBut.setText("Get Description");
		descriptionBut.setOpaque(false);
		descriptionBut.addActionListener(this);

		editOffer = new JButton();
		editOffer.setText("Edit Offer");
		editOffer.setOpaque(false);
		editOffer.addActionListener(this);

		projectMaker = new JButton();
		projectMaker.setText("Make Project");
		projectMaker.setOpaque(false);
		projectMaker.addActionListener(this);

		changeStatus = new JButton();
		changeStatus.setText("Change Status");
		changeStatus.setOpaque(false);
		changeStatus.addActionListener(this);

		offerSearch = new JTextField();
		offerSearch.getDocument().addDocumentListener(new DocumentListener()
		{

			@Override
			public void changedUpdate(DocumentEvent arg0)
			{
				searchOffers();

			}

			@Override
			public void insertUpdate(DocumentEvent arg0)
			{
				searchOffers();

			}

			@Override
			public void removeUpdate(DocumentEvent arg0)
			{
				searchOffers();

			}

		}
				);

		searchBy = new JLabel("Search for:");

		searchWith = new JLabel("Search with:");


		allOfferSearch = new JComboBox<String>();
		allOfferSearch.addActionListener(this);
		allOfferSearch.addItem("Everything");
		allOfferSearch.addItem("Name");
		allOfferSearch.addItem("Drawing Number");
		allOfferSearch.addItem("Quantity");
		allOfferSearch.addItem("Price");
		allOfferSearch.addItem("Deadline");
		allOfferSearch.addItem("Customer");
		allOfferSearch.addItem("Country");
		allOfferSearch.addItem("City");

		active = new JCheckBox("Active");
		active.setOpaque(false);
		active.addActionListener(this);

		svCtrl = new OfferController();
		cusCtrl = new CustomerController();
		subCtrl = new SubContractorController();
		pjCtrl = new ProjectController();

		String allOfferColumns[] = { "#", "Name" , "Drawing Number", "Dimension", "Quantity", "Price", "Deadline", "Customer", "City", "Country", " "};

		allOfferTableModel = new DefaultTableModel(null, allOfferColumns);

		allOfferTable = new JTable(allOfferTableModel)
		{
			private static final long serialVersionUID = 1L;

			public boolean isCellEditable(int rowIndex, int colIndex)
			{
				return false;
			}

			public Class<?> getColumnClass(int column)   
			{   
				return getValueAt(0, column).getClass();   
			}  
		};

		Dimension d = allOfferTable.getPreferredSize();
		double width = d.width / allOfferColumns.length;
		double [] width_2 = {0.1, 1.0, 1.3, 1.0, 0.5, 0.5, 0.6, 0.6, 0.6, 0.8, 0.2};

		for (int i = 0; i < allOfferColumns.length; i++)
			allOfferTable.getColumnModel().getColumn(i).setPreferredWidth((int) (width*width_2[i]));

		allOfferTable.setAutoCreateRowSorter(true);

		allOfferTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		allOfferTableScroll = new JScrollPane(allOfferTable);

		tabbedPane.add(allOffers, "All Offers");
		GroupLayout gl_allReqs = new GroupLayout(allOffers);
		gl_allReqs.setHorizontalGroup(
				gl_allReqs.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_allReqs.createSequentialGroup()
						.addGap(10)
						.addGroup(gl_allReqs.createParallelGroup(Alignment.LEADING, false)
								.addComponent(allOfferTableScroll, GroupLayout.PREFERRED_SIZE, 771, GroupLayout.PREFERRED_SIZE)
								.addGroup(gl_allReqs.createSequentialGroup()
										.addGroup(gl_allReqs.createParallelGroup(Alignment.LEADING)
												.addGroup(gl_allReqs.createSequentialGroup()
														.addComponent(searchWith)
														.addGap(4)
														.addComponent(allOfferSearch, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
														.addGap(6)
														.addComponent(active))
														.addGroup(gl_allReqs.createSequentialGroup()
																.addComponent(searchBy)
																.addGap(10)
																.addComponent(offerSearch, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
																.addGap(6)
																.addComponent(emptySearchList, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)))
																.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																.addGroup(gl_allReqs.createParallelGroup(Alignment.LEADING)
																		.addGroup(gl_allReqs.createSequentialGroup()
																				.addComponent(projectMaker, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
																				.addGap(10)
																				.addComponent(changeStatus, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE))
																				.addGroup(gl_allReqs.createSequentialGroup()
																						.addComponent(descriptionBut, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)
																						.addGap(10)
																						.addComponent(editOffer, GroupLayout.PREFERRED_SIZE, 111, GroupLayout.PREFERRED_SIZE)))))
																						.addContainerGap(14, Short.MAX_VALUE))
				);
		gl_allReqs.setVerticalGroup(
				gl_allReqs.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_allReqs.createSequentialGroup()
						.addContainerGap()
						.addGroup(gl_allReqs.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_allReqs.createSequentialGroup()
										.addGroup(gl_allReqs.createParallelGroup(Alignment.LEADING)
												.addGroup(gl_allReqs.createSequentialGroup()
														.addGap(4)
														.addComponent(searchWith))
														.addGroup(gl_allReqs.createSequentialGroup()
																.addGap(1)
																.addComponent(allOfferSearch, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
																.addComponent(active))
																.addGap(6)
																.addGroup(gl_allReqs.createParallelGroup(Alignment.LEADING)
																		.addGroup(gl_allReqs.createSequentialGroup()
																				.addGap(4)
																				.addComponent(searchBy))
																				.addGroup(gl_allReqs.createSequentialGroup()
																						.addGap(1)
																						.addComponent(offerSearch, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
																						.addComponent(emptySearchList)))
																						.addGroup(gl_allReqs.createSequentialGroup()
																								.addGroup(gl_allReqs.createParallelGroup(Alignment.LEADING)
																										.addComponent(projectMaker)
																										.addComponent(changeStatus))
																										.addGap(6)
																										.addGroup(gl_allReqs.createParallelGroup(Alignment.LEADING)
																												.addComponent(descriptionBut)
																												.addComponent(editOffer))))
																												.addPreferredGap(ComponentPlacement.RELATED)
																												.addComponent(allOfferTableScroll, GroupLayout.PREFERRED_SIZE, 184, GroupLayout.PREFERRED_SIZE)
																												.addGap(8))
				);
		allOffers.setLayout(gl_allReqs);

		// new Offer panel

		newOffers = new ImagePanel(image);
		newOffers.setBounds(0,31,694, 289);

		offers_1 = new JLabel("Name:");
		offerDrawNo = new JLabel("Drawing Number:");
		offerQuantity = new JLabel("Quantity:");
		offerDescr = new JLabel("Description:");
		offerCus = new JLabel("Customer:");
		offerPrice = new JLabel("Price:");

		cal = new JCalendar();
		cal.setBorder(new TitledBorder(null, "Deadline", TitledBorder.LEADING, TitledBorder.BELOW_TOP, null, null));

		offerField = new JTextField();
		offerDrawNoField = new JTextField();
		offerQuantityField = new JTextField();

		try
		{
			cusList = cusCtrl.getAllCustomers();
		}
		catch (SQLException e1)
		{
			e1.printStackTrace();
		}

		newOfferCustomerSelection = new JComboBox<String>();
		newOfferCustomerSelection.addActionListener(this);
		for (int i = 0; i < cusList.size(); i++)
		{
			newOfferCustomerSelection.addItem(cusList.get(i).getUsername());
		}

		createOffer = new JButton();
		createOffer.setText("Create Offer");
		createOffer.setOpaque(false);
		createOffer.addActionListener(this);

		tabbedPane.add(newOffers, "New Offers");

		dimensionText = new JTextField();
		dimensionText.setColumns(10);

		priceText = new JTextField();
		priceText.setColumns(10);

		dimensionLabel = new JLabel("Dimension:");

		offerDescrField = new JTextPane();

		descrScroll = new JScrollPane();



		GroupLayout gl_newReqs = new GroupLayout(newOffers);
		gl_newReqs.setHorizontalGroup(
				gl_newReqs.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_newReqs.createSequentialGroup()
						.addGap(113)
						.addGroup(gl_newReqs.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_newReqs.createSequentialGroup()
										.addGroup(gl_newReqs.createParallelGroup(Alignment.LEADING)
												.addComponent(offers_1)
												.addComponent(offerDrawNo)
												.addComponent(offerQuantity)
												.addComponent(offerDescr)
												.addGroup(gl_newReqs.createSequentialGroup()
														.addGap(1)
														.addGroup(gl_newReqs.createParallelGroup(Alignment.LEADING)
																.addComponent(dimensionLabel, GroupLayout.PREFERRED_SIZE, 57, GroupLayout.PREFERRED_SIZE)
																.addComponent(offerPrice)
																.addComponent(offerCus))
																.addGap(25)))
																.addGroup(gl_newReqs.createParallelGroup(Alignment.LEADING)
																		.addGroup(gl_newReqs.createSequentialGroup()
																				.addGroup(gl_newReqs.createParallelGroup(Alignment.LEADING, false)
																						.addGroup(gl_newReqs.createSequentialGroup()
																								.addGap(16)
																								.addGroup(gl_newReqs.createParallelGroup(Alignment.LEADING)
																										.addComponent(offerField, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE)
																										.addComponent(offerDrawNoField, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE)
																										.addComponent(offerQuantityField, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE))
																										.addGap(10))
																										.addGroup(Alignment.TRAILING, gl_newReqs.createSequentialGroup()
																												.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																												.addComponent(descrScroll, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE)
																												.addGap(9))
																												.addGroup(Alignment.TRAILING, gl_newReqs.createSequentialGroup()
																														.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																														.addComponent(priceText, 250, 250, 250)
																														.addGap(9)))
																														.addComponent(cal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
																														.addGroup(gl_newReqs.createSequentialGroup()
																																.addGap(17)
																																.addComponent(dimensionText, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE)
																																.addGap(70)
																																.addComponent(createOffer))))
																																.addGroup(gl_newReqs.createSequentialGroup()
																																		.addGap(99)
																																		.addComponent(newOfferCustomerSelection, GroupLayout.PREFERRED_SIZE, 250, GroupLayout.PREFERRED_SIZE)))
																																		.addContainerGap(113, Short.MAX_VALUE))
				);
		gl_newReqs.setVerticalGroup(
				gl_newReqs.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_newReqs.createSequentialGroup()
						.addContainerGap()
						.addGroup(gl_newReqs.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_newReqs.createSequentialGroup()
										.addGroup(gl_newReqs.createParallelGroup(Alignment.LEADING)
												.addGroup(gl_newReqs.createSequentialGroup()
														.addGap(4)
														.addComponent(offers_1)
														.addGap(11)
														.addComponent(offerDrawNo)
														.addGap(15)
														.addComponent(offerQuantity)
														.addGap(17)
														.addComponent(offerDescr))
														.addGroup(gl_newReqs.createSequentialGroup()
																.addGap(1)
																.addComponent(offerField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																.addGap(6)
																.addComponent(offerDrawNoField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																.addGap(8)
																.addComponent(offerQuantityField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																.addGap(11)
																.addComponent(descrScroll, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
																.addGap(11)
																.addGroup(gl_newReqs.createParallelGroup(Alignment.BASELINE)
																		.addComponent(priceText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																		.addComponent(offerPrice))
																		.addGap(9)
																		.addGroup(gl_newReqs.createParallelGroup(Alignment.BASELINE)
																				.addComponent(dimensionText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																				.addComponent(dimensionLabel))))
																				.addGap(9)
																				.addGroup(gl_newReqs.createParallelGroup(Alignment.BASELINE)
																						.addComponent(newOfferCustomerSelection, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																						.addComponent(offerCus))
																						.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
																						.addGroup(gl_newReqs.createSequentialGroup()
																								.addComponent(cal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																								.addPreferredGap(ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
																								.addComponent(createOffer)
																								.addGap(20))))
				);
		newOffers.setLayout(gl_newReqs);
		descrScroll.setViewportView(offerDescrField);

		try
		{
			updateOfferList();
			updateCus(newOfferCustomerSelection);

			btnBack = new JButton();
			btnBack.addActionListener(this);
			btnBack.setText("Back");
			btnBack.setOpaque(false);
			btnBack.setBounds(10, 325, 100, 20);

			frameOfferUI.getContentPane().add(btnBack);

			btnPrint = new JButton();
			btnPrint.addActionListener(this);
			btnPrint.setText("Print");
			btnPrint.setOpaque(false);
			btnPrint.setBounds(579, 325, 100, 20);
			frameOfferUI.getContentPane().add(btnPrint);


		}
		catch(Exception e)
		{
			msgError(null, "Could not load information");
		}
	}
	private void updateOfferList()
	{
		try
		{
			offerList = svCtrl.searchServicesByAllInfo(true, active.isSelected(), "");
			allOffersUpdateTable(offerList);
		}
		catch(Exception e)
		{
			msgError(allOffers, "Could not load requests properly");
		}
	}
	public void updateCus(JComboBox<String> comboBox)
	{
		comboBox.removeAllItems();

		ArrayList<Customer> customerList = cusList;

		for(Customer cus : customerList)
			comboBox.addItem(cus.getUsername());
	}



	@Override
	public void actionPerformed(ActionEvent e)
	{
		frameOfferUI.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

		if(e.getSource() == createOffer)
		{
			addOffer();
		}
		else if(e.getSource() == emptySearchList)
		{
			allOfferSearch.setSelectedIndex(0);
			offerSearch.setText(null);
		}
		else if(e.getSource() == editOffer)
		{
			showEditOfferDialog();
		}
		else if(e.getSource() == statistics)
		{
			StatisticsUI stats = StatisticsUI.getInstance();
			stats.display();
			frameOfferUI.setVisible(false);
		}
		else if(e.getSource() == allOfferSearch)
		{
			if(startup)
				searchOffers();
		}
		else if(e.getSource() == descriptionBut)
		{
			getDescription();
		}
		else if(e.getSource() == changeStatus)
		{
			changeStatus();
		}
		else if(e.getSource() == active)
		{
			searchOffers();
		}
		else if(e.getSource() == projectMaker)
		{
			tableList();
			price.clear();
			makeProject();
		}
		else if(e.getSource() == add)
		{
			boolean check = checkInfoGeneral(prices);
			if(check)
			{
				price.add(Double.parseDouble(prices.getText().trim()));
				allSubsTable();
				prices.setText(null);
			}
			else
			{
				msgError(allOffers, "You did not input the subcontractor price properly");
			}
		}
		else if(e.getSource() == btnBack)
		{
			back.goBack(back.getNumber());
		}
		else if (e.getSource() == btnPrint)
		{
			printOfferPDF();
		}

		frameOfferUI.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
	}
	private void printOfferPDF()
	{
		if (allOfferTable.getRowCount() > 0)
		{
			ArrayList<ArrayList<String>> list = new ArrayList<ArrayList<String>>();

			String columns[] = { "#", "Name" , "Drawing Number", "Dimension", "Quantity", "Price", "Deadline", "Customer", "City", "Country" };

			ArrayList<String> offerID = new ArrayList<String>();
			ArrayList<String> offerName = new ArrayList<String>();
			ArrayList<String> offerDrawingNo = new ArrayList<String>();
			ArrayList<String> offerDimension = new ArrayList<String>();
			ArrayList<String> offerQuantity = new ArrayList<String>();
			ArrayList<String> offerPrice = new ArrayList<String>();
			ArrayList<String> offerDeadline = new ArrayList<String>();
			ArrayList<String> offerCustomer = new ArrayList<String>();
			ArrayList<String> offerCity = new ArrayList<String>();
			ArrayList<String> offerCountry = new ArrayList<String>();

			list.add(offerID);
			list.add(offerName);
			list.add(offerDrawingNo);
			list.add(offerDimension);
			list.add(offerQuantity);
			list.add(offerPrice);
			list.add(offerDeadline);
			list.add(offerCustomer);
			list.add(offerCity);
			list.add(offerCountry);

			for(int i = 0; i < allOfferTable.getRowCount(); i++)
			{
				list.get(0).add(String.valueOf(allOfferTable.getValueAt(i, 0)));
				list.get(1).add(String.valueOf(allOfferTable.getValueAt(i, 1)));
				list.get(2).add(String.valueOf(allOfferTable.getValueAt(i, 2)));
				list.get(3).add(String.valueOf(allOfferTable.getValueAt(i, 3)));
				list.get(4).add(String.valueOf(allOfferTable.getValueAt(i, 4)));
				list.get(5).add(String.valueOf(allOfferTable.getValueAt(i, 5)));
				list.get(6).add(String.valueOf(allOfferTable.getValueAt(i, 6)));
				list.get(7).add(String.valueOf(allOfferTable.getValueAt(i, 7)));
				list.get(8).add(String.valueOf(allOfferTable.getValueAt(i, 8)));
				list.get(9).add(String.valueOf(allOfferTable.getValueAt(i, 9)));
			}

			PdfFilePrint pdfPrint = new PdfFilePrint();
			boolean successPDF = pdfPrint.PDFPrint("Offer", "Current offers", "offer", "Nikola", columns, list);

			if(successPDF)
				msgSuccess(null, "PDF was created successfully");
			else
				msgError(null, "There was an error creating the PDF");
		}
		else
		{
			msgError(null, "Nothing to print");
		}
	}

	private boolean checkNull(JTextField textField)
	{
		if((textField.getText().trim().length() == 0 ))
			return false;

		return true;
	}
	private boolean checkInfoName(JTextField textField)
	{

		if((textField.getText().trim().length() == 0) || (textField.getText().trim().length() > 32))
			return false;

		return true;
	}
	private boolean checkInfoGeneral(JTextField textField)
	{

		if((textField.getText().trim().length() == 0) && textField.getText().matches("\\d*"))
			return false;

		return true;
	}
	private boolean checkInfoDimensions(JTextField textField)
	{

		if((textField.getText().trim().length() == 0) || (textField.getText().trim().length() > 52))
			return false;

		return true;
	}

	private void addOffer()
	{
		boolean checkName = checkInfoName(offerField);

		boolean checkDimension = checkInfoDimensions(dimensionText);

		boolean checkQuantity = checkInfoGeneral(offerQuantityField);

		boolean checkDrawing = checkInfoGeneral(offerDrawNoField);

		boolean checkPrice = checkInfoGeneral(priceText);

		if(checkName && checkDimension && checkQuantity && checkDrawing && checkPrice)
		{
			try
			{
				Customer cusObj = new Customer();
				try
				{
					cusObj = cusCtrl.searchCustomerByName(newOfferCustomerSelection.getSelectedItem().toString());
				} catch (SQLException e)
				{
					msgError(newOffers, "Could not load customer information");
					e.printStackTrace();
				}

				int good = svCtrl.addNewService(0,true,offerField.getText().trim(), Integer.parseInt(offerDrawNoField.getText().trim()), Double.parseDouble(priceText.getText().trim()),dimensionText.getText().trim() ,Integer.parseInt(offerQuantityField.getText().trim()), offerDescrField.getText(), cal.getPeriod(), cusObj);

				if(good > 0)
				{
					msgSuccess(newOffers, "Offer \"" + offerField.getText().trim() + "\" has been added successfully");

					offerField.setText(null);
					offerDrawNoField.setText(null);
					offerQuantityField.setText(null);
					offerDescrField.setText(null);
					dimensionText.setText(null);

					searchOffers();
				} // end of if
				else if(good < 0)
				{
					msgError(newOffers, "There was an error adding the offer.\n");
				} // end of else
			}
			// end of try
			catch(Exception ex)
			{
				ex.printStackTrace();
				msgError(newOffers, "There was an error adding the offer.");
			}
		}
		else
		{
			msgError(newOffers, "You cannot proceed due to errors in your input. \n Please check and try again");
		}
	}
	private void showEditOfferDialog()
	{
		if(allOfferTable.getSelectedRow() > -1)
		{
			int offerID = Integer.valueOf(String.valueOf(allOfferTable.getValueAt(allOfferTable.getSelectedRow(), 0)));

			Service offer = new Service();

			try
			{
				offer = svCtrl.getOne(offerID);
			} 
			catch(SQLException e)
			{
				msgError(newOffers, "Cannot retrieve needed information");
				e.printStackTrace();
			}

			JPanel paneled = new JPanel();

			JTextField editOfferName = new JTextField(offer.getName());
			JTextField editOfferDrawNo = new JTextField(String.valueOf(offer.getDrawingNo()));
			JTextField editOfferQuantity = new JTextField(String.valueOf(offer.getProdQuantity()));
			JTextField editOfferDimension = new JTextField(offer.getDimensions());
			JTextPane editOfferDescription = new JTextPane();
			editOfferDescription.setText(offer.getDescription());

			JScrollPane scrollPane_descri = new JScrollPane(editOfferDescription);
			scrollPane_descri.setViewportView(editOfferDescription);
			scrollPane_descri.setPreferredSize(new Dimension(50, 50));
			scrollPane_descri.setLocation(0, 0);

			JCalendar editCal = new JCalendar();
			editCal.setBorder(new TitledBorder(null, "Deadline:", TitledBorder.LEADING, TitledBorder.BELOW_TOP, null, null));
			JComboBox <String> editCustomer = newOfferCustomerSelection;

			updateCus(editCustomer);

			JLabel lblName = new JLabel("Name:");
			JLabel lblDrawingNumber = new JLabel("Drawing Number:");
			JLabel lblQuantity = new JLabel("Quantity:");
			JLabel lblDimension = new JLabel("Dimension:");
			JLabel lblDescription = new JLabel("Description:");
			JLabel lblCustomer = new JLabel("Customer:");

			GroupLayout panel = new GroupLayout(paneled);
			panel.setHorizontalGroup(
					panel.createParallelGroup(Alignment.LEADING)
					.addGroup(panel.createSequentialGroup()
							.addGap(10)
							.addGroup(panel.createParallelGroup(Alignment.LEADING)
									.addComponent(lblName)
									.addComponent(lblDrawingNumber)
									.addComponent(lblQuantity)
									.addComponent(lblDimension)
									.addComponent(lblDescription)
									.addComponent(lblCustomer))
									.addGap(20)
									.addGroup(panel.createParallelGroup(Alignment.LEADING)
											.addGroup(panel.createSequentialGroup()
													.addPreferredGap(ComponentPlacement.RELATED)
													.addGroup(panel.createParallelGroup(Alignment.LEADING)
															.addComponent(scrollPane_descri, 250, 250,250)
															.addComponent(editCustomer, 0, 125, Short.MAX_VALUE)
															.addComponent(editOfferDimension, GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)))
															.addComponent(editOfferQuantity, 150, 150, 150)
															.addGroup(panel.createParallelGroup(Alignment.LEADING, false)
																	.addComponent(editOfferDrawNo)
																	.addComponent(editOfferName, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)))
																	.addGap(18)
																	.addComponent(editCal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																	.addGap(50))
					);
			panel.setVerticalGroup(
					panel.createParallelGroup(Alignment.LEADING)
					.addGroup(panel.createSequentialGroup()
							.addGroup(panel.createParallelGroup(Alignment.LEADING)
									.addGroup(panel.createSequentialGroup()
											.addGap(15)
											.addGroup(panel.createParallelGroup(Alignment.BASELINE)
													.addComponent(lblName)
													.addComponent(editOfferName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
													.addPreferredGap(ComponentPlacement.RELATED)
													.addGroup(panel.createParallelGroup(Alignment.BASELINE)
															.addComponent(lblDrawingNumber)
															.addComponent(editOfferDrawNo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
															.addPreferredGap(ComponentPlacement.RELATED)
															.addGroup(panel.createParallelGroup(Alignment.BASELINE)
																	.addComponent(lblQuantity)
																	.addComponent(editOfferQuantity, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
																	.addPreferredGap(ComponentPlacement.RELATED)
																	.addGroup(panel.createParallelGroup(Alignment.BASELINE)
																			.addComponent(lblDimension)
																			.addComponent(editOfferDimension, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
																			.addPreferredGap(ComponentPlacement.RELATED)
																			.addGroup(panel.createParallelGroup(Alignment.BASELINE)
																					.addComponent(lblDescription)
																					.addComponent(scrollPane_descri, 125,125,125))
																					.addPreferredGap(ComponentPlacement.RELATED)
																					.addGroup(panel.createParallelGroup(Alignment.BASELINE)
																							.addComponent(lblCustomer)
																							.addComponent(editCustomer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
																							.addGroup(panel.createSequentialGroup()
																									.addContainerGap()
																									.addComponent(editCal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
																									.addContainerGap(15, Short.MAX_VALUE))
					);
			paneled.setLayout(panel);

			int option = JOptionPane.showConfirmDialog(allOffers, paneled,"Edit Offer", JOptionPane.OK_CANCEL_OPTION);

			if(option == JOptionPane.YES_OPTION)
			{
				boolean checkName = checkInfoName(editOfferName);
				boolean checkDimension = checkInfoDimensions(editOfferDimension);
				boolean checkQuantity = checkInfoGeneral(editOfferQuantity);
				boolean checkDrawing = checkInfoGeneral(editOfferDrawNo);

				if(checkName && checkDimension && checkQuantity && checkDrawing)
				{
					Customer cusObj = new Customer();

					try
					{
						cusObj = cusCtrl.searchCustomerByName(editCustomer.getSelectedItem().toString().trim());
					}
					catch(Exception e)
					{
						msgError(allOffers, "Cannot retrieve needed information");
					}
					int success = -1;

					try
					{
						success = svCtrl.updateService(false,offerID,editOfferName.getText(),0,editOfferDimension.getText(), Integer.parseInt(editOfferDrawNo.getText().trim()), Integer.parseInt(editOfferQuantity.getText().trim()), editOfferDescription.getText(), editCal.getPeriod(), cusObj);

					}
					catch (SQLException e)
					{
						msgError(allOffers, "There was an error while editing the offer");
					}

					if(success > 0)
					{
						msgSuccess(allOffers, "Offer " + editOfferName.getText().trim() + " has been edited successfully");

						searchOffers();
					}
					else 
					{
						msgError(allOffers, "Offer  has not been edited successfully");
					}
				}
				else
				{
					msgError(allOffers, "The information you have inserted is not correct, please try again");
				}
			}
		}
		else
		{
			msgError(allOffers, "You have not selected an Offer");
		}
	}

	private void allOffersUpdateTable(ArrayList<Service> reqLister)
	{
		if(reqLister.size() > 0)
		{
			tableClearList();

			for(Service offer : reqLister)
			{
				allOfferTableModel.addRow(
						new Object[]
								{

								offer.getServiceID(),
								offer.getName(),
								offer.getDrawingNo(),
								offer.getDimensions(),
								offer.getProdQuantity(),
								offer.getPrice(),
								offer.getDeadline(),
								offer.getCustomer().getUsername(),
								offer.getCustomer().getCity(),
								offer.getCustomer().getCity().getCountry(),
								new ImageIcon("img/flags/" + offer.getCustomer().getCity().getCountry().getTld() + ".png")
								}
						);
			} // end of for
		} // end of if
	}

	private void allSubsTable()
	{

		SubContractor sb = new SubContractor();
		try
		{
			sb = subCtrl.searchSubContractorByName(subContractor.getSelectedItem().toString());
		} catch (SQLException e)
		{
			msgError(allOffers,"The subContractor cannot be added properly");
			e.printStackTrace();
		}

		allSubsModel.addRow(
				new Object[]
						{
						sb.getOutsiderID(),
						sb.getName()

						});
	}

	private void tableClearList()
	{
		DefaultTableModel dTM = (DefaultTableModel) allOfferTable.getModel();

		while(dTM.getRowCount() > 0)
			dTM.removeRow(0);
	}
	private void tableList()
	{
		while(allSubsModel.getRowCount() > 0)
			allSubsModel.removeRow(0);
	}

	private void searchOffers()
	{

		String clause = allOfferSearch.getSelectedItem().toString().toLowerCase();
		String search = offerSearch.getText();

		try
		{
			tableClearList();

			if(search.length() > 0);
			{
				switch(clause)
				{
					case "everything" : offerList = svCtrl.searchServicesByAllInfo(true,active.isSelected(), search); break;
					case "name" : offerList = svCtrl.searchServicesByName(search, active.isSelected(), true); break;
					case "quantity" : offerList = svCtrl.searchServicesByProdQuantity(Integer.parseInt(search), active.isSelected(), true); break;
					case "drawing number" : offerList = svCtrl.searchServicesByDrawingNo(Integer.parseInt(search), active.isSelected(),true); break;
					case "dimensions" : offerList = svCtrl.searchServicesByDimension(search, active.isSelected(), true); break;
					case "customer" : offerList = svCtrl.searchServicesByCustomer(search, active.isSelected(), true); break;
					case "deadline" : offerList = svCtrl.searchServicesByDeadline(search, active.isSelected(), true); break;
					case "country" : offerList = svCtrl.searchServicesByCountry(search, active.isSelected(), true); break;
					case "country tld" : offerList = svCtrl.searchServicesByCountryTld(search, active.isSelected(), true); break;
					case "city" : offerList = svCtrl.searchServicesByCity(search, active.isSelected(), true); break;
					case "price" : offerList = svCtrl.searchServiceByPrice(Double.parseDouble(search), active.isSelected(), true);
				} // end of switch					
				allOffersUpdateTable(offerList);
			}

		} // end of try
		catch(Exception e)
		{
			msgError(allOffers, "Could not load requests");
			e.printStackTrace();
		} // end of catch

		if(!startup)
			startup = true;

	}

	private void changeStatus()
	{

		if(allOfferTable.getSelectedRow() > -1)
		{
			int reqID = Integer.valueOf(String.valueOf(allOfferTable.getValueAt(allOfferTable.getSelectedRow(), 0)));

			JPanel panel = new JPanel(new GridLayout(0,2,5,5));

			JComboBox <String> reqStatus = new JComboBox<String>();
			reqStatus.addItem("Active");
			reqStatus.addItem("Unactive");

			panel.add(reqStatus);

			int option = JOptionPane.showConfirmDialog(allOffers,panel, "Change Status", JOptionPane.OK_CANCEL_OPTION);

			if(option == JOptionPane.YES_OPTION)
			{
				int success = 0;
				switch(reqStatus.getSelectedItem().toString().toLowerCase())
				{
					case "active" : try
					{
						success	 = svCtrl.changeStatus(1, reqID);
					} catch (SQLException e)
					{
						msgError(allOffers, "Could not modify the information, please try again");
						e.printStackTrace();
					}
					break;
					case "unactive" :try
					{
						success = svCtrl.changeStatus(0, reqID);

					} catch(SQLException e)
					{
						msgError(allOffers, "Could not modify the information, please try again");
						e.printStackTrace();
					}
				}
				if(success > 0)
				{
					msgSuccess(allOffers, "Offer has been edited successfully");
					searchOffers();
				}
				else
				{
					msgError(allOffers, "There was an error while editing the offer");
				}

			}


		}
		else
		{
			msgError(allOffers, "You have not selected an offer");
		}
	}

	private void getDescription()
	{

		if(allOfferTable.getSelectedRow() > -1)
		{
			int reqID = Integer.valueOf(String.valueOf(allOfferTable.getValueAt(allOfferTable.getSelectedRow(), 0)));

			Service offer = new Service();
			try
			{
				offer = svCtrl.getOne(reqID);
			}
			catch(SQLException e)
			{
				msgError(allOffers, "Cannoted retrieve needed information");
				e.printStackTrace();
			}
			JTextPane reqDescrField_1 = new JTextPane();
			reqDescrField_1.setText(offer.getDescription());
			JScrollPane scrollPane_1 = new JScrollPane(reqDescrField_1);
			scrollPane_1.setViewportView(reqDescrField_1);
			scrollPane_1.setPreferredSize(new Dimension(150, 150));
			scrollPane_1.setLocation(0, 0);
			JOptionPane.showConfirmDialog(allOffers,scrollPane_1, "Description", JOptionPane.DEFAULT_OPTION);

		}
		else
		{
			msgError(allOffers, "You have not selected an offer");
		}
	}

	private void makeProject()
	{
		if(allOfferTable.getSelectedRow() > -1)
		{
			int offerID = Integer.valueOf(String.valueOf(allOfferTable.getValueAt(allOfferTable.getSelectedRow(), 0)));

			Service offer = new Service();
			sub = new ArrayList<SubContractor>();

			try
			{
				offer = svCtrl.getOne(offerID);
			} catch(SQLException e)
			{
				msgError(allOffers, "Cannot retrieve needed information");
				e.printStackTrace();
			}

			try
			{
				sub = subCtrl.searchSubContractorAll();
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}

			JPanel panel = new JPanel();

			JLabel lblProjectLink = new JLabel();
			lblProjectLink.setText("Project Link:");

			JLabel lblProjectComments = new JLabel();
			lblProjectComments.setText("Project Comments:");

			JLabel lblProjectSubcontractors = new JLabel();
			lblProjectSubcontractors.setText("Project subContractors:");

			JLabel lblProjectSubprice = new JLabel();
			lblProjectSubprice.setText("Price");

			projLink = new JTextField();

			prices = new JTextField();

			JTextPane projComments = new JTextPane();
			JScrollPane projCom = new JScrollPane();
			projCom.setPreferredSize(new Dimension(150, 150));
			projCom.setViewportView(projComments);

			subContractor = new JComboBox<String>();
			for (SubContractor sb : sub)
				subContractor.addItem(sb.getName());

			add = new JButton();
			add.setText("Add");
			add.addActionListener(this);



			JTable allSubsTable = new JTable(allSubsModel)
			{
				private static final long serialVersionUID = 1L;

				public boolean isCellEditable(int rowIndex, int colIndex)
				{
					return false;
				}
			};

			Dimension d = allSubsTable.getPreferredSize();
			double width = d.width / column.length;
			double [] width_2 = {0.2,1.2};

			for (int i = 0; i < column.length; i++)
				allSubsTable.getColumnModel().getColumn(i).setPreferredWidth((int) (width*width_2[i]));

			allSubsTable.setAutoCreateRowSorter(true);

			allSubsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

			JScrollPane allSubTableScroll = new JScrollPane(allSubsTable);

			GroupLayout grPanel = new GroupLayout(panel);
			grPanel.setHorizontalGroup(
					grPanel.createParallelGroup(Alignment.LEADING)
					.addGroup(grPanel.createSequentialGroup()
							.addGap(36)
							.addGroup(grPanel.createParallelGroup(Alignment.TRAILING)
									.addGroup(grPanel.createSequentialGroup()
											.addGroup(grPanel.createParallelGroup(Alignment.LEADING)
													.addComponent(lblProjectLink)
													.addComponent(lblProjectComments)
													.addComponent(lblProjectSubcontractors, GroupLayout.PREFERRED_SIZE, 152, GroupLayout.PREFERRED_SIZE))
													.addPreferredGap(ComponentPlacement.RELATED))
													.addGroup(grPanel.createSequentialGroup()
															.addComponent(lblProjectSubprice, GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)
															.addGap(109)))
															.addGroup(grPanel.createParallelGroup(Alignment.LEADING, false)
																	.addGroup(grPanel.createSequentialGroup()
																			.addGroup(grPanel.createParallelGroup(Alignment.LEADING, false)
																					.addComponent(prices)
																					.addComponent(subContractor, 0, 103, Short.MAX_VALUE))
																					.addPreferredGap(ComponentPlacement.UNRELATED)
																					.addComponent(add, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
																					.addPreferredGap(ComponentPlacement.RELATED)
																					.addComponent(allSubTableScroll, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE))
																					.addComponent(projCom, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																					.addComponent(projLink))
																					.addContainerGap(65, Short.MAX_VALUE))
					);
			grPanel.setVerticalGroup(
					grPanel.createParallelGroup(Alignment.LEADING)
					.addGroup(grPanel.createSequentialGroup()
							.addContainerGap()
							.addGroup(grPanel.createParallelGroup(Alignment.LEADING)
									.addGroup(grPanel.createSequentialGroup()
											.addComponent(projLink, GroupLayout.PREFERRED_SIZE, 17, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.UNRELATED)
											.addComponent(projCom, GroupLayout.PREFERRED_SIZE, 82, GroupLayout.PREFERRED_SIZE)
											.addPreferredGap(ComponentPlacement.RELATED)
											.addGroup(grPanel.createParallelGroup(Alignment.LEADING)
													.addComponent(allSubTableScroll, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
													.addGroup(grPanel.createSequentialGroup()
															.addGroup(grPanel.createParallelGroup(Alignment.BASELINE)
																	.addComponent(subContractor, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																	.addComponent(add))
																	.addPreferredGap(ComponentPlacement.RELATED)
																	.addGroup(grPanel.createParallelGroup(Alignment.BASELINE)
																			.addComponent(prices, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
																			.addComponent(lblProjectSubprice)))))
																			.addGroup(grPanel.createSequentialGroup()
																					.addComponent(lblProjectLink)
																					.addPreferredGap(ComponentPlacement.UNRELATED)
																					.addComponent(lblProjectComments))
																					.addGroup(grPanel.createSequentialGroup()
																							.addGap(116)
																							.addComponent(lblProjectSubcontractors)))
																							.addContainerGap(30, Short.MAX_VALUE))
					);
			panel.setLayout(grPanel);


			int option = JOptionPane.showConfirmDialog(allOffers, panel, "Make Project", JOptionPane.OK_CANCEL_OPTION);

			if(option == JOptionPane.YES_OPTION)
			{
				boolean validLink = checkNull(projLink);
				if(validLink)
				{
					try
					{
						System.out.println("TESTER ");
						ArrayList<SubContractor> chosen = new ArrayList<SubContractor>();
						for (int i = 0 ;i < allSubsModel.getRowCount(); i++)
						{
							System.out.println("CODE IS NOT PASSING THROUGH HERE ");
							SubContractor sb = new SubContractor();
							sb.setOutsiderID(Integer.parseInt(String.valueOf(allSubsModel.getValueAt(i, 0))));
							sb.setName((String) allSubsModel.getValueAt(i, 1));
							System.out.println(sb.getName() + sb.getOutsiderID());
							chosen.add(sb);
							System.out.println(chosen.get(i).getName() + chosen.get(i).getOutsiderID());
						}
						System.out.println("TEST IS : ");
						int good = pjCtrl.transferProject(offerID, offer.getName(), offer.getDrawingNo(), offer.getProdQuantity(),offer.getDimensions(), offer.getDescription(), offer.getDeadline(), offer.getCustomer(), offer.getPrice(), projLink.getText(), projComments.getText(),chosen, price);
						if(good > 0)
						{
							searchOffers();
							msgSuccess(allOffers, "Offer \"" + offerField.getText().trim() + "\" has been added successfully");
						} // end of if
						else if(good < 0)
						{
							msgError(allOffers, "There was an error adding the offer.\n");
						} // end of else
					}// end of try
					catch(Exception ex)
					{
						msgError(allOffers, "There was an error adding the offer.");
					}
				}
			}
		}
		else
		{
			msgError(allOffers, "You have not selected a offer");
		}

	}

	public static void main(String[] args) 
	{
		try 
		{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 

			OfferUI offerUI = new OfferUI();
			offerUI.display();
		}
		catch(Exception e)
		{
			System.out.println("[ERROR] Offer Menu cannot load");
			e.printStackTrace();
		}
	}


	public static OfferUI getInstance()
	{
		if(instance == null)
			instance = new OfferUI();

		return instance;
	}

	private void msgError(JPanel panel, String error)
	{
		JOptionPane.showConfirmDialog(panel, error, "Error", JOptionPane.PLAIN_MESSAGE, JOptionPane.ERROR_MESSAGE);
	}

	private void msgSuccess(JPanel panel, String success)
	{
		JOptionPane.showMessageDialog(panel, success, "Success", 1);
	}
}

